package account.drools;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import account.command.CommandException;
import account.command.GetDrlCommand;

/**
 * Servlet implementation class DroolsResources
 */
@WebServlet("/DroolsResources")
public class DroolsResources extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public DroolsResources() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doProcess(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doProcess(request, response);
	}

	protected void doProcess(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		GetDrlCommand command = new GetDrlCommand();
		String drl = "";
		try {
			command.execute();
			drl = command.outModel.getContent();
		} catch (CommandException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		response.getOutputStream().println( drl );
		
		/*
		response.getOutputStream().println(
				"package account.model\n" +
				 
				"import account.model.AccountModel;\n" +
				 
				"rule \"Hello World\"\n" +
				 "   when\n" +
				 "       m : AccountModel( value == 200 )\n" +
				 "   then\n" +
				 "       m.setName( \"Goodbye2 cruel world\" );\n" +
				"end\n"

				);
				*/
	}	
	
}
